package com.oscar.springaidemo.ai.config;

import com.alibaba.cloud.ai.graph.CompileConfig;
import com.alibaba.cloud.ai.graph.CompiledGraph;
import com.alibaba.cloud.ai.graph.OverAllState;
import com.alibaba.cloud.ai.graph.StateGraph;
import com.alibaba.cloud.ai.graph.action.EdgeAction;
import com.alibaba.cloud.ai.graph.exception.GraphStateException;
import io.micrometer.observation.ObservationRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class CustomerServiceController {

    private CompiledGraph compiledGraph;

    public CustomerServiceController(@Qualifier("workflowGraph") StateGraph stateGraph,
                                     ObjectProvider<ObservationRegistry> observationRegistry) throws GraphStateException {
        this.compiledGraph = stateGraph.compile(CompileConfig.builder()
                .build());
    }

    public static class FeedbackQuestionDispatcher implements EdgeAction {
        @Override
        public String apply(OverAllState t) throws Exception {
            log.info("feedback:{}",t.data());
            return "positive";
        }
    }

    public static class SpecificQuestionDispatcher implements EdgeAction {
        @Override
        public String apply(OverAllState t) throws Exception {
            log.info("specific:{}",t.data());
            return "negative";
        }
    }
}
